<template>
  <div>
    <div class="goodsindex">
      <!-- 搜索条件 -->
      <el-row :gutter="20" class="goodsindex-queryInfo">
        <el-col :xs="8" :sm="5" :md="5" :lg="5" :xl="5">
          <el-input
            class="goodsindex-queryInfo-li"
            v-model="queryInfo.productName"
            clearable
            size="small"
            placeholder="请输入产品序号"
          ></el-input>
        </el-col>
        <el-col :xs="8" :sm="5" :md="5" :lg="5" :xl="5">
          <el-input
            class="goodsindex-queryInfo-li"
            v-model="queryInfo.userCompany"
            clearable
            size="small"
            placeholder="请输入用户名称"
          ></el-input>
        </el-col>
        <!-- <el-col :xs="8" :sm="5" :md="5" :lg="5" :xl="5">
          <el-select v-model="queryInfo.evaluate" size="small" clearable placeholder="评价">
            <el-option label="满意" value="1"></el-option>
            <el-option label="不满意" value="0"></el-option>
          </el-select>

        </el-col> -->
        <el-col :xs="6" :sm="4" :md="3" :lg="2" :xl="2">
          <el-button
            type="primary"
            class="goodsindex-queryInfo-li"
            size="small"
            @click="select"
            >搜索</el-button
          >
        </el-col>
        <!-- <el-col :xs="6" :sm="4" :md="3" :lg="2" :xl="2">
          <el-button type="primary" class="goodsindex-queryInfo-li" size="small" @click="exportFun">导出</el-button>
        </el-col>-->
        <!-- <el-col
          :xs="6"
          :sm="4"
          :md="3"
          :lg="2"
          :xl="2"
          v-if="isAuth('sys:feedback:save')"
        >
          <el-button
            type="primary"
            class="goodsindex-queryInfo-li"
            size="small"
            @click="addOrUpdatehandle()"
            >添加</el-button
          >
        </el-col>-->
      </el-row>
      <!-- 检索结果 -->
      <el-row :gutter="20" class="goodsindex-list">
        <el-col :span="24" class="goodsindex-list-col">
          <el-table
            :data="menuList"
            style="width: 100%"
            :height="tableMaxHeight"
            border
          >
            <el-table-column
              type="index"
              header-align="center"
              align="center"
              label="序号"
              width="50"
            >
            </el-table-column>
            <el-table-column
              prop="productName"
              label="产品序号"
              sortable
              header-align="center"
            />
            <el-table-column
              prop="userCompany"
              label="用户名称"
              header-align="center"
            />
            <el-table-column
              prop="userName"
              label="姓名"
              header-align="center"
            />
            <el-table-column
              prop="userPhone"
              label="电话"
              header-align="center"
            />
            <el-table-column
              prop="userAddress"
              label="地址"
              header-align="center"
            />
            <el-table-column
              prop="handleState"
              label="处理状态"
              header-align="center"
              sortable
              align="center"
            >
              <template #default="scope">
                <el-tag type="danger" v-if="scope.row.handleState == 0"
                  >待处理</el-tag
                >
                <el-tag type="danger" v-if="scope.row.handleState == 2"
                  >处理中</el-tag
                >
                <el-tag v-if="scope.row.handleState == 1">已处理</el-tag>
              </template>
            </el-table-column>
            <el-table-column
              prop="handUserName"
              label="处理人"
              header-align="center"
            />
            <el-table-column
              prop="handleDesc"
              label="处理描述"
              header-align="center"
            />
            <el-table-column
              prop="handleState"
              label="评价"
              header-align="center"
              align="center"
            >
              <template #default="scope">
                <el-tag
                  type="danger"
                  v-if="scope.row.evaluate == 0 && scope.row.evaluate !== ''"
                  >不满意</el-tag
                >
                <el-tag v-if="scope.row.evaluate == 1">满意</el-tag>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              width="160"
              fixed="right"
            >
              <template #default="scope">
                <el-button
                  v-if="isAuth('sys:feedback:look')"
                  size="mini"
                  @click="lookhandle(scope.row.id)"
                  >查看</el-button
                >
                <el-button
                  v-if="
                    isAuth('sys:feedback:sure') && scope.row.handleState == 0
                  "
                  size="mini"
                  type="primary"
                  @click="confirm(scope.row.id)"
                  >确认</el-button
                >
                <el-button
                  v-if="
                    isAuth('sys:feedback:handle') && scope.row.handleState == 2
                  "
                  size="mini"
                  type="primary"
                  @click="handle(scope.row.id, scope.row.handleState)"
                  >处理</el-button
                >
                <el-button
                  v-if="
                    isAuth('sys:feedback:updata') && scope.row.handleState == 1
                  "
                  size="mini"
                  type="primary"
                  @click="handleUpdata(scope.row.id, scope.row.handleState)"
                  >修改</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <!-- 分页 -->
      <el-row :gutter="20">
        <el-col :span="24" style="display: flex; justify-content: flex-end">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageIndex"
            :page-sizes="[1, 10, 20, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalPage"
          >
          </el-pagination>
        </el-col>
      </el-row>
      <userAddorUpdata
        v-if="userAddorUpdataVisible"
        ref="userAddorUpdata"
        @getMenuList="getMenuList"
      ></userAddorUpdata>
      <look v-if="lookVisible" ref="look" @getMenuList="getMenuList"></look>
      <handle
        v-if="handleVisible"
        ref="handle"
        @getMenuList="getMenuList"
      ></handle>
      <handleUpdata
        v-if="handleUpdataVisible"
        ref="handleUpdata"
        @getMenuList="getMenuList"
      ></handleUpdata>
    </div>
  </div>
</template>

<script>
import { treeDmodelataTranslate } from "../../utils/treeDataTranslate.js";
import userAddorUpdata from "./addorupdate.vue";
import look from "./look.vue";
import handle from "./handle.vue";
import handleUpdata from "./handleUpdata.vue";
export default {
  components: {
    userAddorUpdata,
    handle,
    look,
    handleUpdata,
  },
  data() {
    return {
      userAddorUpdataVisible: false, //菜单权限
      lookVisible: false,
      tableData: [],
      dataForm: {},
      menuList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      addOrUpdateVisible: false,
      handleVisible: false,
      handleUpdataVisible: false,
      tableHeight: "",
      queryInfo: {
        evaluate: "",
        productName: "",
        userCompany: "",
      },
    };
  },
  computed: {
    tableMaxHeight() {
      return window.innerHeight - 180 + "px";
    },
  },
  created() {
    this.getMenuList();
  },
  methods: {
    //搜素
    async select() {
      this.pageIndex = 1;
      await this.getMenuList();
    },
    exportFun() {
      this.Sevice({
        url: "syn/Feedback/export",
        method: "POST",
        params: {
          userCompany: this.queryInfo.userCompany,
          productName: this.queryInfo.productName,
        },
        headers: { "Content-Type": "multipart/form-data" },
        responseType: "blob",
      })
        .then((response) => {
          let blob = new Blob([response.data], {
            type: "application/vnd.ms-excel",
          });
          let objectUrl = URL.createObjectURL(blob); // 创建URL
          const link = document.createElement("a");
          link.href = objectUrl;
          // link.download = '.xlsx'// 自定义文件名
          //这里是获取后台传过来的文件名
          link.setAttribute("download", "用户反馈.xlsx");
          link.click(); // 下载文件
          URL.revokeObjectURL(objectUrl); // 释放内存
          isload = objectUrl;
        })
        .catch((err) => {
          isload = "";
          console.log(err);
        });
    },
    getMenuList() {
      this.Sevice({
        url: "syn/Feedback/list",
        method: "get",
        params: {
          userCompany: this.queryInfo.userCompany,
          productName: this.queryInfo.productName,
        },
      })
        .then(async (res) => {
          if (res && res.code == 200) {
            // res.data.sort(function (a, b) {
            //   return a.createTime < b.createTime ? 1 : -1;
            // });
            this.menuList = res.list;
            this.totalPage = this.menuList.length;
            this.menuList = this.menuList.slice(
              (this.pageIndex - 1) * this.pageSize,
              this.pageIndex * this.pageSize
            );
          } else {
            this.menuList = [];
            this.totalPage = 0;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 新增 / 修改
    addOrUpdatehandle(id) {
      this.userAddorUpdataVisible = true;
      this.$nextTick(() => {
        this.$refs.userAddorUpdata.init(id);
      });
    },
    lookhandle(id) {
      this.lookVisible = true;
      this.$nextTick(() => {
        this.$refs.look.init(id);
      });
    },
    //确认
    confirm(id) {
      this.Sevice({
        url: "syn/Feedback/sign",
        method: "post",
        data: {
          id: id,
          handleState: 2,
        },
      })
        .then((res) => {
          if (res && res.code == 200) {
            this.$message({
              type: "success",
              message: "确认成功!",
            });
            this.getMenuList();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //处理
    handle(id, handleState) {
      this.handleVisible = true;
      this.$nextTick(() => {
        this.$refs.handle.init(id, handleState);
      });
    },
    handleUpdata(id, handleState) {
      this.handleUpdataVisible = true;
      this.$nextTick(() => {
        this.$refs.handleUpdata.init(id, handleState);
      });
    },
    //删除
    handleDelete(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.Sevice({
            url: "syn/Feedback/delete",
            method: "post",
            data: [id],
          })
            .then((res) => {
              if (res && res.code == 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.getMenuList();
              }
            })
            .catch((err) => {
              console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.getMenuList();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getMenuList();
    },
  },
};
</script>

<style scoped>
.goodsindex {
  width: 100%;
  min-height: 100%;
  padding: 15px;
  box-sizing: border-box;
}

/* 搜索 */
.goodsindex-queryInfo {
  margin-bottom: 10px;
}

.goodsindex-queryInfo-li {
  width: 100%;
  height: auto;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 列表 */
.goodsindex-list {
  width: 100%;
  height: auto;
  margin-left: 0 !important;
  margin-right: 0 !important;
  margin-bottom: 20px;
}

.goodsindex-list-col {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* 分页 */
.goodsindex-page-box {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: flex-end;
}
</style>
